package com.keur.money.data.analyse.util

import com.keur.money.base.utils.log.MullaLog
import com.keur.money.data.analyse.AnalyseBuilder
import com.keur.money.http.HttpHelper
import com.keur.money.http.IHttpCallback
import org.json.JSONObject

object UrlHelper {

    fun combineUrl(path: String): String {
        if (AnalyseBuilder.host.isBlank() or
            AnalyseBuilder.zone.isBlank() or
            AnalyseBuilder.pathCommon.isBlank()
        ) {
            return ""
        }

        val zone = AnalyseBuilder.zone
        AnalyseBuilder.zone = zone.replace("/", "")

//        val pathCommon = AnalysisBuilder.pathCommon
//        AnalysisBuilder.pathCommon = if (pathCommon.startsWith("/")) {
//            pathCommon.replace("/", "")
//        } else {
//            pathCommon
//        }

        val requestPath = if (path.startsWith("/")){
            path.replace("/","")
        } else {
            path
        }
//        return AnalysisBuilder.host + "/" + AnalysisBuilder.zone + "/" + AnalysisBuilder.pathCommon
        return AnalyseBuilder.host + "/" + AnalyseBuilder.zone + "/" + requestPath
    }
}

object AnalysisHttpHelper {
    fun doPostAction(toUrl: String, body: String) {
        if (toUrl.isBlank()) return
        if (body.isBlank()) return

        MullaLog.i("Analyse Url：  $toUrl")
        MullaLog.i("Analyse Params： $body")


        HttpHelper.postKeurAction(toUrl, JSONObject(body),object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
            }

            override fun onRequestError(error: JSONObject) {
            }

            override fun onRequestFinish() {
            }
        })
//        OkHttp.post<String>(toUrl)
//            .tag(this)
//            .upJson(body)
//            .execute(object : StringCallback() {
//                override fun onSuccess(response: Response<String>) {
//                    Thread { MullaLog.i("Analyse Response：${JsonFormat.format(response.body())}") }.start()
//                }
//                override fun onError(response: Response<String>) {
//                }
//                override fun onFinish() {
//                }
//            })
    }
}


